package com.qfedu.aunt.commons.service.impl;

import com.alibaba.druid.util.StringUtils;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qfedu.aunt.commons.exception.BusinessException;
import com.qfedu.aunt.commons.pojo.Agent;
import com.qfedu.aunt.commons.mapper.AgentMapper;
import com.qfedu.aunt.commons.result.ResponseCode;
import com.qfedu.aunt.commons.service.AgentService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 经纪人表 服务实现类
 * </p>
 *
 * @author xiaobobo
 * @since 2022-10-26
 */
@Service
public class AgentServiceImpl extends ServiceImpl<AgentMapper, Agent> implements AgentService {

    @Autowired
    private AgentMapper agentMapper;

    @Override
    public IPage<Agent> findAgentByCityNameAndPage(String cityName, Integer currentPage, Integer pageSize) {
        if(StringUtils.isEmpty(cityName)||
                null==currentPage||null==pageSize){
            throw new BusinessException(ResponseCode.PARAMETER_ERROR.getCode(),
                    ResponseCode.PARAMETER_ERROR.getMessage());
        }
        //执行到这里说明参数没有问题
        IPage<Agent> page=new Page<>();
        page.setCurrent(currentPage);
        page.setPages(pageSize);

        //构建查询条件
        QueryWrapper<Agent> agentQueryWrapper = new QueryWrapper<>();
        agentQueryWrapper.eq("city_name",cityName);

        IPage<Agent> agentIPage = agentMapper.selectPage(page, agentQueryWrapper);
        return agentIPage;
    }
}
